<!--作者：靳晓璐 -->
<template>
  <div>
    <Leftbar>
    </Leftbar>
    <Headers_copy>
    </Headers_copy>

    <div class="blog">
      <el-button type="primary" plain icon="el-icon-edit" >
        <el-link href="http://localhost:8081/#/blog/add"  style="color: #333333;text-decoration: none">新建博客</el-link>
      </el-button>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="博客简介">
                <span>{{ props.row.summary }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column
            label="博客名称">
          <template slot-scope="props">
            <el-button type="text" @click="getarticle(props.row.aid)"><span content="name" >
            {{props.row.title}}
          </span></el-button>
          </template>
        </el-table-column>
        <el-table-column
            label="编辑时间"
        >
          <template slot-scope="props">
          <span content="time">
            {{props.row.editTime}}
          </span>
          </template>
        </el-table-column>
        <el-table-column
            label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button type="primary"plain icon="el-icon-edit" ></el-button>
              <el-button type="primary"plain icon="el-icon-delete" @click="DeleteArticle(scope.row.aid)"></el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import Leftbar from "../components/Leftbar";
import Headers_copy from "@/components/headers_copy";
import request from "../utils/request";
const axios = require('axios');
export default {
  name:"Blog",
  components: {

    Headers_copy,
    Leftbar,
  },
  data() {
    return {
      uid: sessionStorage.getItem("uid"),
      tableData: [],

    }
  },
  created() {
    const _this=this
    axios.get("http://47.107.40.143:8080/getSpecArticle",{params:{uid:this.uid,state:1}}).then(res =>{
      _this.tableData=res.data.data


      console.log(res)
    })
  },
  methods: {

    getarticle(s){
      this.$router.push(
          {
            name:'BlogDetail',
            query:{aid:s}
          }
      )
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    DeleteArticle(aid){
      axios.get("http://47.107.40.143:8080/deleteArticle",{params:{aid:aid}}).then(res=>{
        console.log(res)
        window.location.reload()
      })
    }


  }
}
</script>

<style scoped>
.blog{
  margin-left: 250px;
  margin-top: 15px;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>